/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ipostservices.services;

import ipostservices.model.bean.Project;
import ipostservices.model.bean.User;
import ipostservices.model.dao.ProjectDAO;
import ipostservices.util.Constantes;
import java.util.List;

/**
 *
 * @author sixviv
 */
public class ProjectSrv {
    ProjectDAO pDAO = new ProjectDAO();

    public String guardar(Project project){
        if(pDAO.insertar(project)){
            return Constantes.EXITO_STR;
        }
        else{
            return Constantes.ERROR_STR;
        }
    }

    public List<Project> getProys(){
        return pDAO.getAll(Project.class);
    }

    public List<Project> getProysUser(int idUser){
        return pDAO.getProys(idUser);
    }

    public Project getProy(int idProy){
        return pDAO.getProysById(idProy);
    }

    public String editar(Project project){
        if(pDAO.actualizar(project)){
            return Constantes.EXITO_STR;
        }
        else{
            return Constantes.ERROR_STR;
        }
    }

    public String eliminar(int idProject){
        Project project = this.getProy(idProject);
        if(pDAO.borrar(project)){
            return Constantes.EXITO_STR;
        }
        else{
            return Constantes.ERROR_STR;
        }
    }
    
    public void setProyUser (User user, int idProy){
        Project project = this.getProy(idProy);
        project.getUsers().add(user);
        this.editar(project);
    }

}
